package markan.blog.me.util;

import java.util.HashMap;
import java.util.Map;

public class MimetypesFileTypeMap {
	
	private final Map<String, String> DB = new HashMap<String, String>();
	
	private static String defaultType = "application/octet-stream";

	public synchronized String getContentMimeType(String filename) {
		int dot_pos = filename.lastIndexOf("."); // period index

		if (dot_pos < 0)
			return defaultType;

		String file_ext = filename.substring(dot_pos + 1);
		if (file_ext.length() == 0)
			return defaultType;

		String result = DB.get(file_ext);
		if (result != null)
			return result;
		
		return defaultType;
	}
	
	public MimetypesFileTypeMap() {
		DB.put("dwg", "application/acad"); 
		DB.put("ccad", "application/clariscad"); 
		DB.put("dxf", "application/dxf"); 
		DB.put("mdb", "application/msaccess"); 
		DB.put("doc", "application/msword"); 
		DB.put("bin", "application/octet-stream"); 
		DB.put("pdf", "application/pdf"); 
		DB.put("ai", "application/postscript"); 
		DB.put("ps", "application/postscript"); 
		DB.put("eps", "application/postscript"); 
		DB.put("rtf", "application/rtf"); 
		DB.put("rtf", "application/rtf"); 
		DB.put("xls", "application/vnd.ms-excel"); 
		DB.put("ppt", "application/vnd.ms-powerpoint"); 
		DB.put("cdf", "application/x-cdf"); 
		DB.put("csh", "application/x-csh"); 
		DB.put("csh", "application/x-csh"); 
		DB.put("dvi", "application/x-dvi"); 
		DB.put("js", "application/x-javascript"); 
		DB.put("latex", "application/x-latex"); 
		DB.put("mif", "application/x-mif"); 
		DB.put("xls", "application/x-msexcel"); 
		DB.put("ppt", "application/x-mspowerpoint"); 
		DB.put("tcl", "application/x-tcl"); 
		DB.put("tex", "application/x-tex"); 
		DB.put("texinfo", "application/x-texinfo"); 
		DB.put("texi", "application/x-texinfo"); 
		DB.put("t", "application/x-troff"); 
		DB.put("tr", "application/x-troff"); 
		DB.put("roff", "application/x-troff"); 
		DB.put("man", "application/x-troff-man"); 
		DB.put("me", "application/x-troff-me"); 
		DB.put("ms", "application/x-troff-ms"); 
		DB.put("src", "application/x-wais-source"); 
		DB.put("zip", "application/zip"); 
		DB.put("au", "audio/basic"); 
		DB.put("snd", "audio/basic"); 
		DB.put("aif", "audio/x-aiff"); 
		DB.put("aiff", "audio/x-aiff"); 
		DB.put("aifc", "audio/x-aiff"); 
		DB.put("wav", "audio/x-wav"); 
		DB.put("gif", "image/gif"); 
		DB.put("ief", "image/ief"); 
		DB.put("jpeg", "image/jpeg"); 
		DB.put("jpg", "image/jpeg"); 
		DB.put("jpe", "image/jpeg"); 
		DB.put("tiff", "image/tiff"); 
		DB.put("tif", "image/tiff"); 
		DB.put("png", "image/png"); 
		DB.put("ras", "image/x-cmu-raster"); 
		DB.put("pnm", "image/x-portable-anymap"); 
		DB.put("pbm", "image/x-portable-bitmap"); 
		DB.put("pgm", "image/x-portable-graymap"); 
		DB.put("ppm", "image/x-portable-pixmap"); 
		DB.put("rgb", "image/x-rgb"); 
		DB.put("xbm", "image/x-xbitmap"); 
		DB.put("xpm", "image/x-xpixmap"); 
		DB.put("xwd", "image/x-xwindowdump"); 
		DB.put("gzip", "multipart/x-gzip"); 
		DB.put("zip", "multipart/x-zip"); 
		DB.put("css", "text/css"); 
		DB.put("html", "text/html"); 
		DB.put("htm", "text/html"); 
		DB.put("txt", "text/plain"); 
		DB.put("rtx", "text/richtext"); 
		DB.put("tsv", "text/tab-separated-values"); 
		DB.put("xml", "text/xml"); 
		DB.put("etx", "text/x-setext"); 
		DB.put("xsl", "text/xsl"); 
		DB.put("mpeg", "video/mpeg"); 
		DB.put("mpg", "video/mpeg"); 
		DB.put("mpe", "video/mpeg"); 
		DB.put("mov", "video/quicktime"); 
		DB.put("qt", "video/quicktime"); 
		DB.put("avi", "video/x-msvideo"); 
		DB.put("movie", "video/x-sgi-movie"); 
		DB.put("swf", "application/x-shockwave-flash"); 
	}
}
